inflation_gdp = wdi[, .( general_inflation =   geo_mean(1 + NY.GDP.DEFL.KD.ZG/100) -1 ) , by = country]
inflation = merge(inflation_computer, inflation_gdp, by = "country")
library(data.table)
library(ggplot2)
library(gridExtra)
library(reshape2)
library(matrixStats)
library(reshape2)
library(here)
library(magrittr)
text.size = 10
dir = here()
# GDP Inflation
wd = gsub("Figures", "Data/World Bank", dir)
setwd(wd)
wdi = fread("wdi.csv") %>% na.omit()
wdi = wdi[country %in% gr$Country & year %in% 1995:2001]
# selected Computer Deflator
##################################################################
wd = gsub("Figures", "Data/OECD_computer_deflator", dir)
setwd(wd)
inflation_computer = fread("computers_price_change.csv")
# remove nationa inflation from computer price index
# mean inflation rate, 1995 - 2001
geo_mean = function(x){ exp(mean(log(x)))}
inflation_gdp = wdi[, .( general_inflation =   geo_mean(1 + NY.GDP.DEFL.KD.ZG/100) -1 ) , by = country]
inflation = merge(inflation_computer, inflation_gdp, by = "country")
View(inflation)
inflation$computer_quality = inflation$general_inflation - inflation$computer_inflation
View(inflation)
inflation$country =   reorder(inflation$country , inflation$computer_quality, FUN= max)
box = ggplot() +
geom_bar(data = gr, aes(x = country, y = computer_quality, fill = country), stat="identity") +
theme_bw() +
theme(panel.border = element_rect(color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none",
plot.title = element_text(face = "bold", hjust = 0.5, size = rel(0.9), vjust = -0.5),
axis.line = element_line(color = "black"),
axis.title.x = element_blank(),
axis.title.y = element_text(vjust= 1, size=rel(0.9)),
axis.text.x = element_text(margin=margin(5,5,3,0,"pt"), angle = 45, hjust = 1),
axis.text.y = element_text(margin=margin(3,5,0,3,"pt")),
axis.ticks.length = unit(-0.7, "mm"),
text=element_text(size = text.size, family="Times"))
box = ggplot() +
geom_bar(data = inflation, aes(x = country, y = computer_quality, fill = country), stat="identity") +
theme_bw() +
theme(panel.border = element_rect(color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none",
plot.title = element_text(face = "bold", hjust = 0.5, size = rel(0.9), vjust = -0.5),
axis.line = element_line(color = "black"),
axis.title.x = element_blank(),
axis.title.y = element_text(vjust= 1, size=rel(0.9)),
axis.text.x = element_text(margin=margin(5,5,3,0,"pt"), angle = 45, hjust = 1),
axis.text.y = element_text(margin=margin(3,5,0,3,"pt")),
axis.ticks.length = unit(-0.7, "mm"),
text=element_text(size = text.size, family="Times"))
box
growth_func = function(t){  (1 + inflation$computer_quality)^(t)  }
t = 0:30
quantity = sapply(t, growth_func)
View(quantity)
quantity = sapply(t, growth_func) %>% t(.)  %>% as.data.table(.)
names(quantity) = as.character(gr$Country)
quantity$time = t
names(quantity) = as.character(inflation$country)
View(inflation)
names(quantity) = as.character(inflation$country)
quantity = sapply(t, growth_func) %>% t(.)  %>% as.data.table(.)
names(quantity) = as.character(inflation$country)
quantity$time = t
quantity = melt(quantity, id.vars = "time")
names(quantity) = c("time", "deflator", "output")
quantity$deflator =   reorder(quantity$deflator, -quantity$output, FUN= max)
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
wdi = wdi[country %in% inflation_computer$country & year %in% 1995:2001]
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
as.character(inflation$country)
View(inflation)
quantity$deflator =   reorder(quantity$deflator, -quantity$output, FUN= max)
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/computers.R')
View(quantity)
quantity = sapply(t, growth_func)
View(quantity)
source('~/Desktop/aggregation/Supplementary Material/Figures/apple_gdp.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/apple_gdp.R')
dir
library(here)
dir = here()
wd = paste(dir, "/clipart")
img <- readPNG("apple.png")
library(data.table)
library(ggplot2)
library(gridExtra)
library(magrittr)
library(png)
library(grid)
library(here)
text.size = 10
dir = here()
w = fread("bread_apple.csv")
d = fread("apple_econ.csv")
gdp_vol = t(t(d)*w$Volume) %>% rowSums()
gdp_vol = gdp_vol/gdp_vol[1]
gdp_mass = t(t(d)*w$Mass) %>% rowSums()
gdp_mass = gdp_mass/gdp_mass[1]
gdp_energy = t(t(d)*w$Energy) %>% rowSums()
gdp_energy = gdp_energy/gdp_energy[1]
gdp = c(gdp_vol, gdp_mass, gdp_energy )
unit  = rep( c("Volume", "Mass", "Energy"), each = 30)
time = rep(1:30, 3)
output = data.table(time, gdp, unit)
d$time = 1:30
wd = paste(dir, "/clipart")
img <- readPNG("apple.png")
apple = rasterGrob(img, interpolate = T)
img <- readPNG("bread.png")
bread = rasterGrob(img, interpolate = T)
setwd(wd)
wd = paste(dir, "/clipart")
setwd(wd)
wd
wd = paste(dir, "/clipart", sep = "")
setwd(wd)
source('~/Desktop/aggregation/Supplementary Material/Figures/apple_gdp.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/apple_gdp.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/apple_gdp.R')
source('~/Desktop/aggregation/Supplementary Material/Figures/prices.R')
wd = wd = gsub("Figures", "Data/Vintage_gdp", dir)
setwd(wd)
g = fread("vintage_gdp.csv")
View(g)
source('~/Desktop/aggregation/Supplementary Material/Data/Vintage_gdp/vintage_workbook.R')
View(final)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
v$value = v$DATE / pop$population
View(v)
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
View(v)
combine = merge(pop, v, by = "DATE")
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
View(combine)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
View(combine)
combine$DATE
v$value = v$value/combine$population
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
v$index = index$index
v = na.omit(v)
View(v)
View(v)
source('~/Desktop/aggregation/Supplementary Material/Data/Vintage_gdp/vintage_workbook.R')
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
v$value = v$value/combine$population
# normalize GDP to 1 in 1947
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
v$index = index$index
v = na.omit(v)
# extend series to present date
##########################################################
# growth rate function
gr = function(x){
d = rev(end(x))
g = x[ -d[1]] / x[ -d[2] ]
g = c(1, g)
return(g)
}
rate = v[, gr(value), by = variable]
v$rate = rate$V1
# max growth
max.series = v$variable[which.max(v$index)]
max.series = v[ variable == max.series ]
geo_mean = function(x){
exp(mean(log(x)))
}
series = unique(v$variable)
l = length(series)
y = unique(v$DATE)
final = NULL
for(i in 1:l){
sub  = v[variable == series[i]]
y.max = max(sub$DATE)
max.sub = max.series[DATE <= y.max]
# add growth rate correction
gr.diff =   geo_mean(max.sub$rate) - geo_mean(sub$rate)
gr.future = max.series$rate[max.series$DATE > y.max]
gr.future = gr.future - gr.diff
predict = cumprod(gr.future)*tail(sub$index,1)
predict = c(sub$index, predict)
output = data.table(series = series[i], year = y, gdp = predict)
final = rbind(final, output)
}
# clean vintage date
###################################################
series = strsplit(final$series, "M") %>% unlist()
series = gsub("[^0-9]", "", series) %>% as.numeric()
odd = seq(1, length(series), 2)
even = seq(2, length(series), 2)
quarter = series[even]/12
year = series[odd] + quarter  + 1900
year[year< 1940] = year[year< 1940] + 100
final$series_year = year
# add spaces between series for ploting
#################################################################
s = unique(final$series)
l = length(s)
space = data.table(NA, NA, NA, NA)
names(space) <- names(final)
result = NULL
for(i in 1:l){
sub = subset(final, series == s[i])
result = rbind(result, space, sub)
}
dir
View(result)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
v$value = v$value/combine$population
# normalize GDP to 1 in 1947
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
v$index = index$index
v = na.omit(v)
View(v)
View(v)
View(combine)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
View(v)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
v$value = v$value/combine$population
View(v)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
names(pop) = c("DATE", "population")
combine = merge(pop, v, by = "DATE")
v$value = v$value/combine$population
# normalize GDP to 1 in 1947
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
v$index = index$index
v = na.omit(v)
View(v)
View(combine)
View(v)
View(v)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
View(v)
v$test = v$variable / pop$population
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
v$test = v$variable / pop$population
v$variable
v$test = v$value / pop$population
View(v)
library(data.table)
library(ggplot2)
library(magrittr)
library(here)
dir = here()
setwd(dir)
# clean data
v = fread("routputMvQd.csv")
m = 1947 + 284/4
y = seq(1947, m - 0.25, 0.25)
v$DATE = y
# long format
v = melt(v, id.vars= "DATE")
v$value = gsub("#N/A","", v$value)
v$value = as.numeric(v$value)
v$variable = as.character(v$variable)
# convert to gdp per capita
wd = gsub("Vintage_gdp", "US_population", dir)
setwd(wd)
pop = fread("us_pop_quarterly.csv")
pop = pop[year %in% y]
v$value = v$value / pop$population
# normalize GDP to 1 in 1947
f = function(x){x/x[1]}
index = v[, .(index = f(value)), by = variable]
v$index = index$index
v = na.omit(v)
View(combine)
View(v)
source('~/Desktop/aggregation/Supplementary Material/Data/Vintage_gdp/vintage_workbook.R')
